package com.muqi.app.qlearn.student.ui;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.Legend.LegendDirection;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.Legend.LegendPosition;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.muqi.app.im.adapter.MyFragmentPagerAdapter;
import com.muqi.app.network.http.MyAsyncHttp;
import com.muqi.app.network.http.ParamsUtils;
import com.muqi.app.network.http.ResponseUtils;
import com.muqi.app.network.http.MyAsyncHttp.AsyncCallBackListener;
import com.muqi.app.network.http.MyAsyncHttp.RESULTCODE;
import com.muqi.app.project.contants.NetWorkApi;
import com.muqi.app.project.utils.NumberFormatUtil;
import com.muqi.app.project.utils.ToastUtil;
import com.muqi.app.qlearn.fragments.AcademicAnalysisFragment;
import com.muqi.app.qlearn.fragments.AcademicLevelFragment;
import com.muqi.app.qlearn.fragments.BannerFragment;
import com.muqi.app.qlearn.fragments.HomeWorkFragment;
import com.muqi.app.qlearn.fragments.NotificationFragment;
import com.muqi.app.qlearn.modles.GrowRewardAndMoveInfo;
import com.muqi.app.qlearn.modles.Priase;
import com.muqi.app.qlearn.modles.StatisticsInfo;
import com.muqi.app.qlearn.modles.Subject;
import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.BaseStudentActivity;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.user.db.ChildBean;
import com.muqi.app.user.widget.SubjectWindow;
import com.muqi.app.user.widget.SubjectWindow.ClickSubjectListener;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.SpannableString;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class AcademicLevelActivity extends BaseFragmentActivity implements
		OnClickListener,ClickSubjectListener {
	private TextView o2oButton;
	private TextView classButton;
	private ViewPager orderPager;
	private ImageView mIvBrush;
	private MyFragmentPagerAdapter mAdapter;
	private List<Fragment> fragmentList = new ArrayList<Fragment>();
	private SubjectWindow subjectWindow;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_academic_level);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		mSpUtil.setNotification(mSpUtil.getCurrentChildId() + "e",
				0);
		
		sendBroadcast(new Intent(BannerFragment.BANNER_EXAMINATION_CHANGED));
		
	}

	@Override
	protected void onInit() {
		o2oButton = (TextView) findViewById(R.id.one2one_button);
		o2oButton.setOnClickListener(this);
		classButton = (TextView) findViewById(R.id.class_button);
		classButton.setOnClickListener(this);
		orderPager = (ViewPager) findViewById(R.id.order_content);
		mIvBrush=(ImageView) findViewById(R.id.iv_brush);
		mIvBrush.setOnClickListener(this);

	}

	@Override
	protected void onData() {
		loadSubject();
		fragmentList.add(new AcademicLevelFragment());
		fragmentList.add(new AcademicAnalysisFragment());
		mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),
				fragmentList);
		orderPager.setAdapter(mAdapter);
		orderPager.addOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				classButton
						.setBackgroundResource(R.drawable.corners_white_5_radus);
				o2oButton
						.setBackgroundResource(R.drawable.corners_white_5_radus);
				classButton
						.setTextColor(getResources().getColor(R.color.white));
				o2oButton.setTextColor(getResources().getColor(R.color.white));
				switch (position) {
				case 0:
					mIvBrush.setVisibility(View.GONE);
					classButton
							.setBackgroundResource(R.drawable.corners_right_bg);
					o2oButton.setTextColor(getResources().getColor(
							R.color.green));
					break;
				case 1:
					mIvBrush.setVisibility(View.VISIBLE);
					o2oButton.setBackgroundResource(R.drawable.corners_left_bg);
					classButton.setTextColor(getResources().getColor(
							R.color.green));
					break;
				}

			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {

			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});

	}
    /**
     *  加载学科数据
     */
	private void loadSubject() {
		
		List<Subject> listData=new ArrayList<Subject>();
		listData.add(new Subject("语文"));
		listData.add(new Subject("数学"));
		listData.add(new Subject("英语"));
		subjectWindow=new SubjectWindow(this, listData, this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.one2one_button:
			orderPager.setCurrentItem(0);
			break;
		case R.id.class_button:
			orderPager.setCurrentItem(1);
			break;
		case R.id.iv_brush:
			if(subjectWindow!=null){
				subjectWindow.showAsDropDown(v);
			}
			
			break;
		default:
			break;
		}

	}

	public void onBack(View v) {
		finish();
	}

	@Override
	public void onClickSubjectListener(int position) {
		((AcademicAnalysisFragment)fragmentList.get(1)).changeSubject();
		
	}

}
